package com.xuzao.developer.service.impl;

import com.github.pagehelper.PageInfo;
import com.xuzao.developer.base.model.AddressServer;
import com.xuzao.developer.utils.JasyptUtil;
import com.xuzao.developer.vo.BaseResultVo;
import com.xuzao.developer.tools.entity.Pager;
import com.xuzao.developer.dao.AddressServerDao;
import com.xuzao.developer.dto.AddressServerDTO;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import com.xuzao.developer.service.AddressServerService;


/**
 * @description 
 * @author xuzao
 * @date 2019-09-03 17:32:07
 **/
@Service("addressServerService")
public class AddressServerServiceImpl implements AddressServerService {

	@Resource
	private AddressServerDao addressServerDao;

	@Override
	public PageInfo<AddressServer> list(AddressServerDTO dto, Pager pager) {
		return addressServerDao.list(dto, pager);
	}

	@Override
	public BaseResultVo insert(AddressServerDTO dto) {
		AddressServer addressServer = new AddressServer();
		BeanUtils.copyProperties(dto,addressServer);
		if (StringUtils.isNotBlank(addressServer.getAddressPassword())){
			addressServer.setAddressPassword(JasyptUtil.encrypt(addressServer.getAddressPassword()));
		}
		Integer count = addressServerDao.insertSelective(addressServer);
		if (count > 0) {
			return BaseResultVo.success();
		}
		return BaseResultVo.error();

	}

	@Override
	public BaseResultVo update(AddressServerDTO dto) {
		AddressServer addressServer = new AddressServer();
		BeanUtils.copyProperties(dto,addressServer);
		if (StringUtils.isNotBlank(addressServer.getAddressPassword())){
			addressServer.setAddressPassword(JasyptUtil.encrypt(addressServer.getAddressPassword()));
		}
		Integer count = addressServerDao.updateSelectiveById(addressServer);
		if (count > 0) {
			return BaseResultVo.success();
		}
		return BaseResultVo.error();
	}

	@Override
	public AddressServer get(Long id) {
		return addressServerDao.selectById(id);
	}

	@Override
	public void del(Long id) {
		addressServerDao.deleteById(id);
	}
}